{% extends "_base_m.html" %}
{% block content %}
<div id="cats">
    <h3>{{ catFlag }} Category</h3>
    <form method="post" action="/manager">
        <input type="hidden" name="act" value="savecat" />
        <input type="hidden" name="key" value="{{ cat.key }}" />
        <p>
            Name:
            <input type="text" name="name" value="{{ cat.name }}" />
        </p>
        <p>
            Sort:
            <input type="text" name="sort" size="4" value="{{ cat.sort }}" />
            <input type="submit" value="{{ catFlag }}" />
            {% ifequal catFlag 'Edit' %}<a href="/manager">Calcel</a>{% endifequal %}
        </p>
    </form>
    
    <ul>
    {% if cats.count %}
        {% for cat in cats %}
        <li>
            <a href="/manager?act=editcat&key={{ cat.key }}" >{{ cat.name|escape }}</a>
            ({{ cat.sort }})
            <a href="/manager?act=delcat&key={{ cat.key }}" onclick="return confirm('確定要刪除嗎?');" >X</a>
        </li>
        {% endfor %}
    {% else %}
        <li>Nothing...</li>
    {% endif %}
    </ul>
    
</div>

<div id="sites">
    <h3>{{ siteFlag }} Site</h3>
    <form method="post" action="/manager">
        <input type="hidden" name="act" value="savesite" />
        <input type="hidden" name="key" value="{{ site.key }}" />
        <p>
            Category:
            <select name="cat">
                <option value="0">Select a category</option>
                {% for cat in cats %}
                <option value="{{cat.key}}" {% ifequal cat.key site.cat.key %}selected{% endifequal %}>{{ cat.name|escape }}</option>
                {% endfor %}
            </select>
            Title:
            <input type="text" name="title" value="{{ site.title|escape }}" />
        </p>
        <p>
            URL:
            <input type="text" name="url" size="30" value="{% firstof site.url 'http://' %}" />
            Sort:
            <input type="text" name="sort" size="4" value="{{ site.sort }}" />
            <input type="submit" value="{{ siteFlag }}" />
            {% ifequal siteFlag 'Edit' %}<a href="/manager">Calcel</a>{% endifequal %}
        </p>
    </form>
    
    <table width="100%" border="2">
        <tr>
            <th scope="col">Category</th>
            <th scope="col">Title</th>
            <th scope="col">URL</th>
            <th scope="col">Sort</th>
            <th scope="col">Manager</th>
        </tr>
        {% if sites.count %}
        {% for site in sites %}
        <tr>
            <td>{{ site.cat.name|escape }}</td>
            <td>{{ site.title|escape }}</td>
            <td>{{ site.url }}</td>
            <td align="right" >{{ site.sort }}</td>
            <td align="center" >
                <a href="/manager?act=editsite&key={{ site.key }}">EDIT</a> |
                <a href="/manager?act=delsite&key={{ site.key }}" onclick="return confirm('確定要刪除嗎?');" >DEL</a></td>
        </tr>
        {% endfor %}
        {% else %}
        <tr>
            <td colspan="5">Nothing...</td>
        </tr>
        {% endif %}
    </table>
</div>
{% endblock %}